//
//  PriceBarView.m
//  JiaoX
//
//  Created by yinqy on 15/1/12.
//  Copyright (c) 2015年 北京娇羞科技有限公司. All rights reserved.
//

#import "PriceBarView.h"

#define NOWPRICE_FONT_SIZE 15
#define OLDPRICE_FONT_SIZE 12

@interface PriceBarView()
{
    UILabel *_nowPriceLabel;
    UILabel *_oldPriceLabel;
    UILabel *_discountLabel;
    UILabel *_buyCountLabel;
    
}
@end

@implementation PriceBarView

-(instancetype)initWithNowPrice:(NSString *)nowPrice oldPrice:(NSString *)oldPrice buyCount:(NSString *)buyCount{
    self = [super init];
    if (self) {
        [self setBounds:CGRectMake(0, 0, JXScreenW, NOWPRICE_FONT_SIZE)];
        
        CGFloat newPriceF = [nowPrice floatValue];
        CGFloat oldPriceF = [oldPrice floatValue];
        
        //现价
        _nowPriceLabel = [UILabel new];
        [_nowPriceLabel setTextColor:JXThemeColor];
        [_nowPriceLabel setFont:[UIFont systemFontOfSize:NOWPRICE_FONT_SIZE]];
        nowPrice = [NSString stringWithFormat:@"￥%@",nowPrice];
        CGSize newPriceSize = [nowPrice sizeWithFont:[UIFont systemFontOfSize:NOWPRICE_FONT_SIZE]];
        [_nowPriceLabel setFrame:CGRectMake(JXPublicInset, 0, newPriceSize.width, NOWPRICE_FONT_SIZE)];
        [_nowPriceLabel setText:nowPrice];
        [self addSubview:_nowPriceLabel];
        
        //原价
        _oldPriceLabel = [UILabel new];
        [_oldPriceLabel setFont:[UIFont systemFontOfSize:OLDPRICE_FONT_SIZE]];
        [_oldPriceLabel setTextColor:JXColor(153, 153, 153)];
        oldPrice = [NSString stringWithFormat:@"￥%@",oldPrice];
        CGSize oldPriceSize = [oldPrice sizeWithFont:[UIFont systemFontOfSize:OLDPRICE_FONT_SIZE]];
        [_oldPriceLabel setFrame:CGRectMake(CGRectGetMaxX(_nowPriceLabel.frame)+JXPublicInset/2, NOWPRICE_FONT_SIZE-OLDPRICE_FONT_SIZE, oldPriceSize.width, OLDPRICE_FONT_SIZE)];
        [_oldPriceLabel setText:oldPrice];
        [self addSubview:_oldPriceLabel];
        
        CGFloat discountF = newPriceF/oldPriceF*10;
        NSString *discount = [NSString stringWithFormat:@"%.2f",discountF];
        //折扣
        _discountLabel = [UILabel new];
        [_discountLabel setFont:[UIFont systemFontOfSize:OLDPRICE_FONT_SIZE]];
        [_discountLabel setTextColor:JXColor(153, 153, 153)];
        discount = [NSString stringWithFormat:@"%@折",discount];
        CGSize discountSize = [discount sizeWithFont:[UIFont systemFontOfSize:OLDPRICE_FONT_SIZE]];
        [_discountLabel setFrame:CGRectMake(CGRectGetMaxX(_oldPriceLabel.frame)+JXPublicInset, NOWPRICE_FONT_SIZE-OLDPRICE_FONT_SIZE, discountSize.width, OLDPRICE_FONT_SIZE)];
        [_discountLabel setText:discount];
        [self addSubview:_discountLabel];
        
        //购买人数
        buyCount = [NSString stringWithFormat:@"%@人购买",buyCount];
        _buyCountLabel = [UILabel new];
        [_buyCountLabel setFont:[UIFont systemFontOfSize:OLDPRICE_FONT_SIZE]];
        [_buyCountLabel setTextColor:JXColor(153, 153, 153)];
        CGSize buyCountSize = [buyCount sizeWithFont:[UIFont systemFontOfSize:OLDPRICE_FONT_SIZE]];
        [_buyCountLabel setFrame:CGRectMake(JXScreenW-JXPublicInset-buyCountSize.width, NOWPRICE_FONT_SIZE-OLDPRICE_FONT_SIZE, buyCountSize.width, OLDPRICE_FONT_SIZE)];
        [_buyCountLabel setText:buyCount];
        [self addSubview:_buyCountLabel];
        
    }
    return self;
}

@end
